package com.baomidou.ant.controller;

import com.baomidou.ant.common.Result;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.*;
import java.net.URL;
import java.util.List;

@RestController
@RequestMapping("/admin")
public class AdminController {
    //项目绝对路径
    private final String relativelyPath=System.getProperty("user.dir");
    //微信配置文件路径----正式部署用
    private final String kdPath=relativelyPath+"\\config\\kdwebapi.properties";
    //微信配置文件路径----开发测试用
//    private final String kdPath=relativelyPath+"\\fpe_production\\src\\main\\resources\\kdwebapi.properties";

    @PostMapping("/getErpSetting")
    public Result getErpSetting(){
        File f = new File("");
        try {
            String path=kdPath;
            FileInputStream fin = new FileInputStream(path);
            InputStreamReader reader = new InputStreamReader(fin);
            BufferedReader buffReader = new BufferedReader(reader);
            String strTmp;
            String result="";
            //逐行读取
            while((strTmp = buffReader.readLine())!=null){
                if(strTmp.contains("#")){
                    continue;
                }else {
                    result=result+strTmp+"\r\n";
                }
            }
            buffReader.close();
            String[] resultList=result.split("\r\n");
            return Result.getSuccess().setData(resultList);
        } catch (IOException e) {
            e.printStackTrace();
            return Result.getFailure();
        }
    }


}
